var _isDeployed = 0;
 
$(document).ready(function() 
   {
$('.rsquare').click(
	$.throttle(2000,function()
	{
		if (_isDeployed==1 && getGameStatus()==1)
		{
			$(this).find('.square1').css('background-color','#CCCCCC');
			if (isValid($(this).attr("id")))
			{
				cellToServer($(this).attr("id"));
				if (_soundEnabled)
				{
					battleshipCannonSound();
				}
			}
		}
	})
);
$('#rdyBtn').click(function()
{	
	
	if (_isDeployed==0)
	{
		if (isDeployed()==10)
		{
			_isDeployed=1;
			$(this).css('background-color','green');
			paint(0,'#CCCCCC');
			deployToServer(getPositionedJP(),getCells(),_isDeployed,getShipLocation());
		}
		else{
			$(this).effect("highlight", {color:"red"}, 1000);
		}
	}
	else
	{
		if (getGameStatus()==0)
		{
			_isDeployed=0;	
			paint(allIllegal(),'red');
			$(this).css('background-color','');
			deployToServer(getPositionedJP(),getCells(),_isDeployed);
		}
			
	}
});	
$('#muteBtn').click(function()
{
	if (_soundEnabled)
	{
		_soundEnabled=false;
		$('#muteBtn').html("Heliga");
	}
	else
	{
		_soundEnabled=true;
		$('#muteBtn').html("Helitu");
	}
});
$('#surrenderBtn').click(function()
{
	surrender();
});
parent.$(".fancybox-item.fancybox-close").click(function()
{
	surrender();
});
InitDragDrop();
initServer();
initGameNumber();

});